# 导入:
from sqlalchemy import Table, MetaData, Column, Integer,Float, Boolean,String, DateTime, ForeignKey, create_engine
from sqlalchemy.orm import sessionmaker,relationship
from sqlalchemy.orm import mapper
from sqlalchemy.ext.declarative import declarative_base

from datetime import datetime
import os

# 创建对象的基类:
Base = declarative_base()

class Terminal(Base):
    __tablename__="terminal"
    id = Column(Integer, primary_key=True)
    name = Column(String(30))
    uuid = Column(String(30))
    position = Column(String(30))
    is_online = Column(Boolean, default=False)
    status = Column(String(30))

class Node(Base):
    __tablename__="node"
    id = Column(Integer, primary_key=True)
    name = Column(String(30))
    uuid = Column(String(30))
    position = Column(String(30))
    is_online = Column(Boolean, default=False)
    status = Column(String(30))

db_init_flag = False
sqlite_db_path = os.getcwd() + '/conf/data.db'
# 初始化数据库连接:
engine = create_engine('sqlite:///%s'%sqlite_db_path)
# 创建数据库
if not os.path.exists(sqlite_db_path):
    Base.metadata.create_all(engine)
    db_init_flag = True
